<template>
  <div class="dashboard">
    <el-row :gutter="10">
      <el-col :span="7">
        <Card title="分类商品数量(饼图)">
          <PieChart :pieData="categoryGoodsCount" />
        </Card>
      </el-col>
      <el-col :span="10">
        <Card title="不同城市商品销量">
          <MapChart :mapData="addressGoodsSale" />
        </Card>
      </el-col>
      <el-col :span="7">
        <Card title="分类商品数量(饼图)">
          <RoseChart :roseData="categoryGoodsCount" />
        </Card>
      </el-col>
    </el-row>
    <el-row :gutter="10" class="content-row">
      <el-col :span="12">
        <Card title="分类商品的销量">
          <LineChart v-bind="categoryGoodsSale" />
        </Card>
      </el-col>
      <el-col :span="12">
        <Card title="分类商品的收藏">
          <BarChart v-bind="categoryGoodsFavor" />
        </Card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import BarChart from '@/components/PageCharts/BarChart.vue'
import LineChart from '@/components/PageCharts/LineChart.vue'
import PieChart from '@/components/PageCharts/PieChart.vue'
import RoseChart from '@/components/PageCharts/RoseChart.vue'
import MapChart from '@/components/PageCharts/MapChart.vue'
import Card from '@/base-ui/Card/Card.vue'
import { useStore } from '@/store'
import { computed } from 'vue'
const store = useStore()
// 请求数据
store.dispatch('chart/getDashboardDataAction')
const categoryGoodsCount = computed(() => {
  return store.state.chart.categoryGoodsCount.map((item: any) => {
    return { name: item.name, value: item.goodsCount }
  })
})
const categoryGoodsSale = computed(() => {
  const xLabels: string[] = []
  const values: any[] = []
  const categoryGoodsSale = store.state.chart.categoryGoodsSale
  for (const item of categoryGoodsSale) {
    xLabels.push(item.name)
    values.push(item.goodsCount)
  }
  return { xLabels, values }
})
const categoryGoodsFavor = computed(() => {
  const xLabels: string[] = []
  const values: any[] = []
  const categoryGoodsFavor = store.state.chart.categoryGoodsFavor
  for (const item of categoryGoodsFavor) {
    xLabels.push(item.name)
    values.push(item.goodsFavor)
  }
  return { xLabels, values }
})
const addressGoodsSale = computed(() => {
  return store.state.chart.addressGoodsSale.map((item: any) => {
    return { name: item.address, value: item.count }
  })
})
</script>

<style scoped lang="less">
.dashboard {
  .content-row {
    margin-top: 20px;
  }
}
</style>
